package com.fyzk.betzhushu.klpk;

import com.fyzk.activity.lottery.shuzicai.BallInfo;
import com.fyzk.betzhushu.ZhuShuBase;
import com.fyzk.utils.LogUtil;

import java.math.BigInteger;
import java.util.List;

public class KLPKRenXuan extends ZhuShuBase{

	private int num = 2;

	public KLPKRenXuan(int num){
		this.num = num;
	}

	@Override
	public long betZhuShu(List<List<BallInfo>> balls) {
		if ((num - 1)>=0 && (num - 1) < balls.size()) {
			List<BallInfo> infos = balls.get(num - 1);
			int selectedNum = 0;
			for (int j = 0; j < infos.size(); j++) {
				BallInfo info = infos.get(j);
				if (info.isSelected()) {
					selectedNum++;
				}
			}
			return getZhuShu_common(selectedNum);
		}

		return 0;
	}
	
	/**
	 * 计算注数(任选n)
	 */
	private long getZhuShu_common(int hong){
		if (hong < num) {
			return 0;
		}else{
			BigInteger big = c_x_y(hong).divide(c_x_y(num)).divide(c_x_y(hong - num));
			return  big.longValue();
		}
	}
	
	private BigInteger c_x_y(int n){
		BigInteger big = new BigInteger(""+n);
		
		return (n == 0) ? new BigInteger("1") : big.multiply(c_x_y(n - 1)) ;
	}

}
